package org.jianghu.activity.splash.view;

import android.os.Bundle;
import android.os.Handler;

import org.jianghu.R;
import org.jianghu.activity.main.view.MainActivity;
import org.jianghu.activity.splash.presenter.WelcomePresenterCompl;
import org.jianghu.base.BaseActivity;
import org.jianghu.utils.IntentUtil;
import org.xutils.view.annotation.ContentView;
import org.xutils.x;

/**
 * Created by Administrator on 2016/12/19.
 *
 */
@ContentView(R.layout.activity_welcome)
public class WelcomeActivity extends BaseActivity implements WelcomeView{

    private static final int SHOW_TIME_MIN = 4000;// 最小显示时间

    private WelcomePresenterCompl welcomePresenterCompl;

    @Override
    public void initViewsAndValues(Bundle savedInstanceState) {

        x.view().inject(this);

        welcomePresenterCompl.isFirstRun();

    }

    @Override
    public void initParmers() {
        welcomePresenterCompl = new WelcomePresenterCompl(this,WelcomeActivity.this);
    }

    @Override
    public void releaseOnDestory() {

    }

    @Override
    public void isFirstRun(boolean isRun) {
        if(isRun){
            //第一次执行程序
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    IntentUtil.intentDIY(WelcomeActivity.this,MainActivity.class);
                    finish();
                }
            },SHOW_TIME_MIN);
        }else{
            //不是第一次执行
            welcomePresenterCompl.saveFirstRun();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    IntentUtil.intentDIY(WelcomeActivity.this,MainActivity.class);
                    finish();
                }
            },SHOW_TIME_MIN);
        }
    }

}
